<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Admin\RoleController;
use App\Http\Controllers\Admin\PermissionController;
use App\Http\Controllers\Admin\OrganizationController;
use App\Http\Controllers\Admin\SystemSettingController;

Route::get('/', function () {
    return view('welcome');
});

// 认证路由
Auth::routes();

// 管理后台路由
Route::prefix('admin')->name('admin.')->group(function () {
    Route::middleware(['auth'])->group(function () {
        Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
        Route::resource('users', UserController::class);
        Route::resource('roles', RoleController::class);
        Route::resource('permissions', PermissionController::class);
        Route::resource('organizations', OrganizationController::class);
    
    // 组织用户管理路由
    Route::post('organizations/{organization}/add-admin', [OrganizationController::class, 'addAdmin'])->name('organizations.add-admin');
    Route::post('organizations/{organization}/add-member', [OrganizationController::class, 'addMember'])->name('organizations.add-member');
    Route::delete('organizations/{organization}/users/{user}', [OrganizationController::class, 'removeUser'])->name('organizations.remove-user');
    Route::post('organizations/{organization}/promote-to-admin', [OrganizationController::class, 'promoteToAdmin'])->name('organizations.promote-to-admin');
    
    // 系统设置路由 - 特殊路由需要在resource之前定义
    Route::post('system-settings/batch-update', [SystemSettingController::class, 'batchUpdate'])->name('system-settings.batch-update');
    Route::post('system-settings/clear-cache', [SystemSettingController::class, 'clearCache'])->name('system-settings.clear-cache');
    Route::get('system-settings/export', [SystemSettingController::class, 'export'])->name('system-settings.export');
    Route::post('system-settings/import', [SystemSettingController::class, 'import'])->name('system-settings.import');
    Route::resource('system-settings', SystemSettingController::class);
    });
});

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
